package com.example.wechat;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.stream.ChunkedWriteHandler;

public class WebServerInItializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        //websocket基于http协议，要编码和解码的方法
        pipeline.addLast(new HttpServerCodec());
        //对于大数据的写的支持
        pipeline.addLast(new ChunkedWriteHandler());
        //对于httpmessage进行聚合
        pipeline.addLast(new HttpObjectAggregator(1024*64));
        //用于支持http
        //==============
        pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
        pipeline.addLast(new WebServerHander());
    }
}
